var xmlhttp = myXMLHttpRequest();

function changeHandlerVereador(){
	e = document.getElementById("filter-vereador");
	c = document.getElementById("filter-categoria");
	a = document.getElementById("filter-ano");
	vereadoId = e.options[e.selectedIndex].value;
	
	c.innerHTML ="<option value='0'>Selecione uma Atividade</option> ";
	a.innerHTML ="<option value='0'>Selecione um ano</option> ";
	
	
	url = '/portal/index.php?option=com_ganeshavereadores&task=abc&format=raw&filter-vereador=' + vereadoId;
	
	params = null;
	xmlhttp.open("GET", url,true);
	
	xmlhttp.onreadystatechange=function() 
	{			
	
		if(xmlhttp.readyState==4)
		{
			c.innerHTML = xmlhttp.responseText;
			
			if(document.getElementById("filter-categoria").options[1]){
				document.getElementById("filter-categoria").options[1].selected=true;
				c.onchange();
				
			}
		}							
	}
	xmlhttp.send(params);
}


function changeHandlerCategoria(){
	e = document.getElementById("filter-vereador");
	c = document.getElementById("filter-categoria");
	a = document.getElementById("filter-ano");
	
	a.innerHTML ="<option value='0'>Selecione um ano</option> ";
	
	vereadoId = e.options[e.selectedIndex].value;
	
	$('filter-ano').html('');
	
	categoriaId = c.options[c.selectedIndex].value;
	
	url = '/portal/index.php?option=com_ganeshavereadores&task=getano&format=raw&filter-vereador='+vereadoId+'&filter-categoria='+categoriaId;
	
	
	params = null;
	xmlhttp.open("GET", url,true);
	
	xmlhttp.onreadystatechange=function() 
	{			
	
		if(xmlhttp.readyState==4)
		{
			document.getElementById("filter-ano").innerHTML=xmlhttp.responseText;
			
			if(document.getElementById("filter-ano").options[1]) {
				document.getElementById("filter-ano").options[1].selected=true;
				
				a.onchange();
			}
			
		}							
	}
	xmlhttp.send(params);
}



function myXMLHttpRequest()
{
	var myxmlhttp;
	try
	{
		myxmlhttp = new XMLHttpRequest();	
		 
		return myxmlhttp;
	}
	catch(ee)
	{
		try
		{
			myxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			
			return myxmlhttp;
		}
		catch(e)
		{
			try
			{
				myxmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				 
				return myxmlhttp;
			}
			catch(E)
			{
				myxmlhttp = false;
			}
		}	
		return myxmlhttp;
	}

 }



	